/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.depaul.se.courseregistration.sessionbean;
import edu.depaul.se.courseregistration.jpa.courses.*;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;

/**
 *
 * @author Group2
 */

@Stateless
@LocalBean
public class DBAdminSession {

    @EJB
    DBAdminEJB dbAdminEJB;
    
    @EJB
    CourseEJB courseEJB;
    
    //DBAdminSession buisness APIs
    //Create, Remove, Update Course
    //@Override
    public Course createCourse(int subjectId, int courseId, String courseTitle, String coursePrerequisite, 
                                           String courseBrief, int quarterNumber,String termTitle, String termYear) {
        //get the subject
        Subject subject = courseEJB.findSubjectById(subjectId);
        
        return dbAdminEJB.createCourse(subject,courseId, courseTitle, coursePrerequisite, 
                                       courseBrief, quarterNumber,termTitle, termYear);
    }
    
    //@Override
    public void removeCourse(int courseNumber)
    {
        dbAdminEJB.removeCourse(courseNumber);
    }
    
    //@Override
    public void updateCourse(int courseId, String courseTitle, String coursePrerequisite, String courseBrief, 
               int quarterNumber,String termTitle, String termYear)
    {
        //Retrive course
       Course courseToUpdate = courseEJB.findCourseById(courseId);
      //Call EJB
        dbAdminEJB.updateCourse(courseToUpdate, courseTitle, coursePrerequisite, courseBrief, 
               quarterNumber,termTitle, termYear);
    }
    
    //Create, Remove, Update Section
    //@Override
    public Section createSection(int courseID, int sectionId,int sectionPrice, boolean isOpen,String instructorName,
            String sectionDates, String meetingHours, String buildingName, String roomNumber) {
       //Retrive section
       Course course = courseEJB.findCourseById(courseID);
       //Call EJB
       return dbAdminEJB.createSection(course, sectionId,sectionPrice, isOpen, instructorName,
               sectionDates,meetingHours,buildingName, roomNumber);
    }
    
   //@Override
    public void removeSection(int courseSectionID)
    {
        dbAdminEJB.removeSection(courseSectionID);
    }
    
    //@Override
    public void updateSection(int sectionID,int sectionPrice, boolean isOpen,String instructorName,
            String sectionDates, String meetingHours, String buildingName, String roomNumber )
    {
      //Retrive section
       Section sectionToUpdate = courseEJB.findSectionById(sectionID);  
      //Call ejb
       dbAdminEJB.updateSection(sectionToUpdate,sectionPrice,isOpen, instructorName, 
                                 sectionDates , meetingHours, buildingName, roomNumber );
    }
    
    //Create Subject
    //@Override
    public Subject createSubject(int collegeID, String subjectCode, String subjectDescription, int subjectid ) {
        //Locate the college
        College college = courseEJB.findCollegeById(collegeID);
        return dbAdminEJB.createSubject(college,subjectCode, subjectDescription , subjectid);
    }
    //@Override
    public void removeSubject(int subjectID)
    {
        dbAdminEJB.removeSubject(subjectID);
    }
    //@Override 
    public void updateSubject(int subjectID, String subjectCode, String subjectDescription)
    {
        //Retrive subject
        Subject subjectToUpdate = courseEJB.findSubjectById(subjectID);
 
        dbAdminEJB.updateSubject(subjectToUpdate, subjectCode,subjectDescription);
    }
    
    //Create College
   //@Override
    public College createCollege(int collegeID, String collegeName, String collegeShortName) {
        
       return dbAdminEJB.createCollege(collegeID,collegeName,collegeShortName);
    }
    
    //@Override
    public void removeCollege(int collegeId)
    {
        dbAdminEJB.removeCollege(collegeId);
    }
    //@Override    
    public void updateCollege(int collegeID, String collegeName, String collegeShortName)
    {
        //Retrieve college
       College collegeToUpdate = courseEJB.findCollegeById(collegeID);
       //Call the ejb      
       dbAdminEJB.updateCollege(collegeToUpdate, collegeName, collegeShortName);
    }
}